<html>
<head>
    <title>SIMILE | Timeline</title>
    <link rel='stylesheet' href='styles.css' type='text/css' />
   <link href="ScriptLibrary/windows_js_0.85.2/themes/default.css" rel="stylesheet" type="text/css">
		<link href="ScriptLibrary/windows_js_0.85.2/themes/theme1.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" type="text/css" href="ScriptLibrary/windows_js_0.85.2/themes/mac_os_x.css">
		<link rel="stylesheet" type="text/css" href="ScriptLibrary/windows_js_0.85.2/themes/alphacube.css">
		<script language="JavaScript" type="text/javascript" src="ScriptLibrary/Atlas/Release/AtlasCompat.js"></script>
		<script language="JavaScript" type="text/javascript" src="ScriptLibrary/Atlas/Release/Atlas.js"></script>
		<script language="JavaScript" type="text/javascript" src="ScriptLibrary/scriptaculous-js-1.6.0/lib/prototype.js"></script>
		<script language="JavaScript" type="text/javascript" src="ScriptLibrary/scriptaculous-js-1.6.0/src/effects.js"></script>
		<script language="JavaScript" type="text/javascript" src="ScriptLibrary/windows_js_0.85.2/javascripts/window.js"></script>
		<script language="JavaScript" type="text/javascript" src="ScriptLibrary/AjaxLabCommandPrompt/Engine/Abstract/CMD.js"></script>
		<script language="JavaScript" type="text/javascript" src="ScriptLibrary/AjaxLabCommandPrompt/Engine/Core/CMD.js"></script>
		<script type="text/javascript">
		
		
		function pageLoad()
		{
			openDebugWindow();
			openCmd();
			
		}
		
		function openCmd()
		{
			var cmd = new AjaxLab.Engine.Core.Cmd("Cmd","CmdPrompt","item","http://www.ajaxlab.com");
			cmd.setIsDebug(false);
			openContentWindow();
		}
		
		function openContentWindow() {

				var contentWin = new Window('content_win', {
														className: "alphacube",
														title: "AjaxLab Command Prompt",
														maximizable: true, 
														resizable: true, 
														closable: false,
														hideEffect:Element.hide, 
														showEffect:Element.show
														}
										)

				var width = $('test_content').offsetWidth;
				var height = $('test_content').offsetHeight;
				contentWin.setContent('test_content', true, true);
				contentWin.setSize(width,height);
				contentWin.setLocation(20,120);
				contentWin.toFront();
				contentWin.setDestroyOnClose();
				contentWin.show();
				//contentWin.showCenter(true);	
				var myObserver = { 
					onEndResize	:	function(eventName, win)
					{
						if(win == contentWin)
						{
							$('CmdPrompt').style.width = win.width-15+"px";
							$('CmdPrompt').style.height = win.height-15+"px";
						}
					}, 
					
					onEndMaximize: function(eventName, win)
					{
						if(win == contentWin)
						{
							$('CmdPrompt').style.width = win.width-15+"px";
							$('CmdPrompt').style.height = win.height-15+"px";
						}
					}
				}
				Windows.addObserver(myObserver);
		}
		
		function openDebugWindow()
		{
				var contentWin = new Window('content_debug', {
														className: "dialog",
														title: "AjaxLab Command Prompt Debug",
														maximizable: true, 
														resizable: true,
														closable: false, 
														hideEffect:Element.hide, 
														showEffect:Element.show
														}
										)
				var width = $('item').style.width;
				var height = $('item').style.height;
				contentWin.setContent('item', true, true);
				contentWin.setLocation(20,120);
				contentWin.setSize(width,height);
				contentWin.toFront();
				contentWin.setDestroyOnClose();
				contentWin.show();	
				var myObserver = { 
					onEndResize	:	function(eventName, win)
					{
						if(win == contentWin)
						{
							$('item').style.width = win.width+"px";
							$('item').style.height = win.height+"px";
						}
					},
					
					onEndMaximize: function(eventName, win)
					{
						if(win == contentWin)
						{
							$('item').style.width = win.width+"px";
							$('item').style.height = win.height+"px";
						}
					}
					
				}
				Windows.addObserver(myObserver);
		}
		
		function BindSelectIPCount()
		{
			AjaxLabCmd.CMDLogParserDemo.SelectIPCount(IPCountCallBack);
		}
		
		function IPCountCallBack(res)
		{
			for(var i=0; i<res.value.Tables[0].Rows.length; i++)
			{
				$("IPCountResult").innerHTML=$("IPCountResult").innerHTML+res.value.Tables[0].Rows[i].IP + " : " + res.value.Tables[0].Rows[i].Total+"<br/>";
			}
		}
		
		</script>
		

	
		<style type="text/css">
	<!--
	.style1 {font-size: 16}
	-->
		</style>
</head>
<body>
		<form runat="server">
		</form>
		<table id="test_content">
			<tr>
				<td>
					<textarea style="BACKGROUND:#000000; COLOR:#ffffff" id="CmdPrompt" cols="80" rows="20" wrap="virtual"></textarea>
				</td>
			</tr>
		</table>
		<div id="item" style="FONT-SIZE:12px; OVERFLOW:scroll; WIDTH:750px; HEIGHT:200px; BACKGROUND-COLOR:black">
		</div>
		<DIV id="myDiv" style="BORDER-RIGHT:red 1px solid; PADDING-RIGHT:2px; BORDER-TOP:red 1px solid; DISPLAY:none; PADDING-LEFT:2px; Z-INDEX:10; LEFT:0px; PADDING-BOTTOM:2px; BORDER-LEFT:red 1px solid; PADDING-TOP:2px; BORDER-BOTTOM:red 1px solid; POSITION:absolute; TOP:0px; BACKGROUND-COLOR:yellow">Suggested 
			text</DIV>
			
<div id="body">
    <h1>Web Stats Custom Plug-In Example </h1>
    <p>This is custom  plug-in for the Command Prompt that allows the users to get the web statistics information using AjaxPro.NET, C# and MSLogParser 2.2 and display the result back to the command prompt. 
    <p>*Note, it's perfectly fine if you use Scriptaculous/PHP/Apache log combo as well. The command prompt is flexible and doesn't care which language platform you choose to develop your own ajax commands. 
      <br>
      <br>
    1. Take a look at the Command Plug-In Template 
    <div>
				  <pre class="style1">  	<br>Type.registerNamespace(&quot;AjaxLab.Engine.Plugins&quot;);<br>AjaxLab.Engine.Plugins.<strong>YourCommandClassName</strong>= function()<br>{<br>	var customCommands = &quot;<strong>YourCommand1|</strong>Yo<strong>urCommand2&quot;</strong>;<br>	var instance = this;<br>	AjaxLab.Engine.Plugins.BaseCommands.initializeBase(this);<br>	this.registerCommands(customCommands);<br>	<br>	/* Implement the Plug In here */<br>	<br>	this.processCommands = function(inputtext) {<br>		<br>		<br>    }<br>}<br>AjaxLab.Engine.Plugins.<strong>YourCommandClassName</strong>.registerClass('AjaxLab.Engine.Plugins.<strong>YourCommandClassName</strong>', AjaxLab.Engine.Abstract.Commands);</pre>
</div>

    <p>All we have to do is to replace the three bolded &quot;YourCommandClassName&quot; with our own class name and the rest is taken cared by the command prompt itself. The bolded <strong>&quot;YourCommand1|YourCommand2&quot;</strong> will be our custom commands. More on this later. <br>
        <br>
      2. Okay, Let's code our IIS Log plugin. <br>
      <br>
      First, let's call our plugin &quot;MSIISLogParser&quot;, so base on the command template above, it becomes <br>
      <br>
<div>
		    <pre class="style1">  	<br>Type.registerNamespace(&quot;AjaxLab.Engine.Plugins&quot;);<br>AjaxLab.Engine.Plugins.<strong>MSIISLogParser</strong>= function()<br>{<br>	var customCommands = <strong>&quot;YourCommand1|YourCommand2&quot;;</strong><br>	var instance = this;<br>	AjaxLab.Engine.Plugins.BaseCommands.initializeBase(this);<br>	this.registerCommands(customCommands);<br>	<br>	/* Implement the Plug In here */<br>	<br>	this.processCommands = function(inputtext) {<br>		<br>		<br>    }<br>}<br>AjaxLab.Engine.Plugins.<strong>MSIISLogParser</strong>.registerClass('AjaxLab.Engine.Plugins.<strong>MSIISLogParser</strong>', AjaxLab.Engine.Abstract.Commands)</pre>
</div>
</p>
<p>3. Register our own commands. <p>Now, Let's add our own commands. I'm thinking of using &quot;webstats&quot; or &quot;logparser&quot;, oh hell, let's use both. So let's replace the bolded <span class="style1"><strong>&quot;YourCommand1|YourCommand2&quot;</strong>with our own then. </span></p>
<div>
		    <pre class="style1">  	<br>Type.registerNamespace(&quot;AjaxLab.Engine.Plugins&quot;);<br>AjaxLab.Engine.Plugins.<strong>MSIISLogParser</strong>= function()<br>{<br>	var customCommands = <strong>&quot;webstats||logparser&quot;;</strong><br>	var instance = this;<br>	AjaxLab.Engine.Plugins.BaseCommands.initializeBase(this);<br>	this.registerCommands(customCommands);<br>	<br>	/* Implement the Plug In here */<br>	<br>	this.processCommands = function(inputtext) {<br>		<br>		<br>    }<br>}<br>AjaxLab.Engine.Plugins.<strong>MSIISLogParser</strong>.registerClass('AjaxLab.Engine.Plugins.<strong>MSIISLogParser</strong>', AjaxLab.Engine.Abstract.Commands)</pre>
</div>

    <br>
    <p>4. How do we know what commands that the user entered? <br>
      <br>
Notice this &quot;this.processCommands&quot; function? That's where we are going to implement our own logic. Command prompt by default, pass the commands that the user entered on each line before they hit the &quot;ENTER&quot; key or carraige return and pass them into the &quot;inputtext&quot; parameter. For example: <br>
<br>
<div>
<pre class="style1"> <br>http://www.AjaxLab.com License LGPL&gt;webstats top visitors

<em><strong>inputtext is &quot;webstats top visitors&quot;</strong></em>
</pre>
</div>
</p>
<br>
5. Process Commands. <br>
<br>
Okay. Now, let' s take &quot;webstats top visitors&quot; command as an example and see how we are going to process it. <br>
<br>
For this plug-in, I decided to use MSLogParser to parse the IIS log files and because MSSLogParser works nicely with C#, I decided to go all .NET with this plugIn and
use AjaxPro.NET as well. (I encourage other plug-ins in scriptaculous/php to be submitted )
<p><br>
<div>
	<pre class="style1">this.processCommands = function(inputtext) {<br>		instance.Log4J.setRootLevel(instance.Log4J.LevelTypes.Debug);<br>		instance.Log4J.Debug(&quot;LogParser command detected and input string is :&quot;+inputtext);<br>		var command     = inputtext.split(&quot; &quot;);<br>		if (command == null)<br>		{<br>			instance.Log4J.Debug(&quot;LogParser Command null&quot;);<br>		}<br>		instance.Log4J.Debug(&quot;Logparser input string command[0]:&quot;+command[0]);<br>		i<em><strong>f(command[0].toUpperCase() == &quot;LOGPARSER&quot; || &quot;WEBSTATS&quot;)</strong></em><br>		{<br>			if(command[1].toUpperCase() <em><strong>== &quot;TO</strong></em>P&quot;)<br>			{<br>				if(command[2].toUpperCase() ==<em><strong>&quot;VISITO</strong></em>RS&quot;)<br>				{<br>					instance.Log4J.Debug(&quot;Start retrieving Top IPCount&quot;);<br>				<em><strong>	AjaxLabCmd.CMDLogParserDemo.SelectTopVisits(command[3],this.IPCountCallBack</strong></em>);<br>				}<br>				else{<br>					instance.Console.printToConsole(command[2]+&quot; is not recognized as an internal or external command&quot;);<br>				}<br>			}<br><br>			else{<br>				instance.Log4J.Debug(&quot;LogParser command :&quot;+command[1]+&quot; not recognized&quot;);<br>				instance.Console.printToConsole(inputtext+&quot; is not recognized as an internal or external command&quot;);<br>			}<br>		}<br>		else{<br>				instance.Log4J.Debug(&quot;LogParser base command not found&quot;);<br>				instance.Console.printToConsole(inputtext+&quot; is not recognized as an internal or external command&quot;);<br>		}<br>    }<p>this.IPCountCallBack = function(res)
{ <br>
		instance.Log4J.Debug(&quot;Start Top Viists Print&quot;);
			instance.Console.println(&quot;&quot;);
			instance.Console.println(&quot;IP			Count&quot;);
			instance.Console.println(&quot;----------		----------&quot;);<br>
			if(res.value.Tables[0]!=null)
			{ 
				for(var i=0; i&lt;res.value.Tables[0].Rows.length; i++)
				{
					instance.Console.println(res.value.Tables[0].Rows[i].IP + &quot;              : &quot; + res.value.Tables[0].Rows[i].Total);
			}
			}
			else{
				instance.Console.println(&quot;No values&quot;);
			}
			instance.Console.newPrompt();
			instance.Log4J.Debug(&quot;Endclear Top Visits Print&quot;);<br>}</pre>
</div>
      <p><br>
</p>
        What's going on Here? If you look closely, it's simply doing simple javascript actions. <br>
        <br>
First, it parses the incoming command &quot;webstats top visitors&quot; into an array sepearated via spaces ( inputtext.split(&quot; &quot;) ).</p>
      <p>Second, if &quot;webstates top visitors&quot;, all three words are found, it calls <span class="style1"><em><strong> <br>
        <br>
      AjaxLabCmd.CMDLogParserDemo.SelectTopVisits(command[3],this.IPCountCallBack</strong></em>);</span><br>
        <br>
        This is a syntax specific to AjaxPro.NET. <strong>AjaxLabCmd</strong> is the backend Namespace.  <em><strong>CMDLogParserDemo </strong></em>is the backend class to parse the IIS Log file. <strong>SelectTopVisits </strong>is the class method that does the specfic query and <strong>this.IPCountCallBack </strong>is the ajax call back method for us to handle the result of the Ajax Query which simply loops through the result and spit it back onto the command prompt screen. <br>
        <br>
        Again, exactly how you call your backend is up to you. You can use Dojo, scriptaculous or whatever is yoru favorite. At this point, the magic is in your hands. <br>
        <br>
        Note, there are serveral default methods that are available to plug-in authors. <br>
        <br>
        1. instance.Log4J.Debug() method is available to you if you want to output some debugging information. <br>
        2. instance.Console.printToConsole() is used to print anything you want onto the console screen. <br>
        3. instance.Console.newPrompt() simply output another prompt root like &quot;c:/:&gt; &quot; or in this demo, it's &quot;http://www.AjaxLab.com License LGPL :&gt;&quot; <br>
        <br>
        <br>
        6. Command List. <br>
        <br>
        Okay,  I won't go into the details as how I developed all the others commands. Here are a list of them that you can try it out here in the demo. <br>
        <br>
<div>

<pre>
  webstats top visitors<br/>
  webstats top NonStandardUserAgent<br/>
  webstats top hits <br/>
  webstats top PossibleAttacks <br/>
  webstats top PageErrors <br/>
  webstats top HitsPerPage <br/>
  webstats top RecordedErrors <br/>
  webstats top BrokenLinks <br/>
  webstats top Win32Errors <br/>
  webstats top HttpMethods <br/>
  webstats top BytesSendToClient <br/>
  webstats top BytesSendFromClient <br/>
  webstats top TimeSpendProcessing<br/>
  webstats successful attempt<br/>
</pre>

</div>

      <h2>Credits</h2>
    <p>AjaxLab.com License LGPL

</p>
</body>
</html>